from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kio import *
from PyKDE4.kdeui import *
from PyKDE4.kdecore import *
from settings_ui import Ui_Dialog
import sys
#Settings for twi-plasmoid
class SettingsDialog(QWidget, Ui_Dialog):

    def __init__(self, parent=None):
        QWidget.__init__(self)
        self.parent=parent
        self.setupUi(self)
        self.readFromFile()
    def get_settings(self):
    #function to return current settings
        return {"user": self.lineEdit.text(), "password": self.lineEdit_2.text()}
    
    def writeToFile(self):
    #It writes currect settings to file
        settingsFile=QSettings('twi.conf',QSettings.IniFormat)
        settingsFile.setValue('username',str(self.lineEdit.text()))
        settingsFile.setValue('password',str(self.lineEdit_2.text()))

    def readFromFile(self):
    #Reads settings from config file and applies them to Settings interface
        settingsFile=QSettings('twi.conf',QSettings.IniFormat)
        self.lineEdit.setText(settingsFile.value('username','').toString())
        self.lineEdit_2.setText(settingsFile.value('password','').toString())
        


